home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.4d7 source / tn3270 / genktab.c < prev    next >
C/C++ Source or Header  |  1992-04-17  |  5KB  |  198 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.4d7  April, 1992
  5.  *  Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #include <StdIO.h>
  34. #include <String.h>
  35.  
  36. unsigned char codeline[128];
  37. unsigned char typebuff[256];
  38. unsigned char databuff[256];
  39. unsigned char aplbuff[256];
  40. unsigned char hexbuff[8];
  41. unsigned char outline[128];
  42.  
  43. unsigned char ebc64[] = {
  44.     0x40,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,
  45.     0xc8,0xc9,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
  46.     0x50,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
  47.     0xd8,0xd9,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
  48.     0x60,0x61,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
  49.     0xe8,0xe9,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
  50.     0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  51.     0xf8,0xf9,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f};
  52.  
  53. main()
  54. {
  55. int i, j, index, i1, i2, lnum;
  56. unsigned char * rc;
  57. unsigned char s1[64];
  58. unsigned char s2[64];
  59. unsigned char s3[64];
  60. unsigned char type, val, apl, ge;
  61. FILE *infile, *outfile, *namefile;
  62.  
  63. for (i=0; i < 256; i++) 
  64.     typebuff[i] = databuff[i] = aplbuff[i] = 0;
  65.     
  66. typebuff[254] = 0x01;        /* 0x01 for ALA support */
  67.  
  68. infile = fopen("keycodes.memo", "r");
  69. if (infile == 0) {
  70.     printf("Error opening keycodes.memo\n");
  71.     return;
  72.     }
  73.     
  74. namefile = fopen("kbnames.new", "w");
  75. if (namefile == 0) {
  76.     printf("Error creating kbnames.new\n");
  77.     return;
  78.     }
  79. fprintf(namefile, "static unsigned char * namelist[] = {\n");
  80.  
  81. rc = fgets(codeline, 128, infile);    /* skip first line */
  82. rc = fgets(codeline, 128, infile);
  83. lnum = 2;
  84. index = 0;
  85. while (rc != 0) {
  86.     sscanf(codeline,
  87.     "%s %x %x %s %s",
  88.     s1, &i1, &i2, s2, s3);
  89.     type = s1[0];
  90.     val = i1;
  91.     apl = i2;
  92.     ge = s2[0];
  93.     fprintf(namefile, "\t/* %03d */\t\"%s\",\n", index, s3);
  94.     switch(type) {
  95.         case 'D':    typebuff[index] = 1;
  96.                 if (ge == 'Y') typebuff[index] += 0x80;
  97.                 break;
  98.         case 'L':    typebuff[index] = 0x41;    /* caps lock works */
  99.                 break;
  100.         case 'A':    typebuff[index] = 2;
  101.                 break;
  102.         case 'C':    typebuff[index] = 3;
  103.                 break;
  104.         default:     break;
  105.         }
  106.     databuff[index] = val;
  107.     aplbuff[index] = apl;
  108.     rc = fgets(codeline, 128, infile);
  109.     lnum++;
  110.     index++;
  111.     }
  112. fprintf(namefile, "\t};");
  113. fclose(namefile);
  114.  
  115. outfile = fopen("kbtables.new", "w");
  116. if (outfile == 0) {
  117.     printf("Error creating kbtables.c\n");
  118.     return;
  119.     }
  120.  
  121. fputs("/* Note: This file is generated by \"genktab\".  Do not edit\n", outfile);
  122. fputs("         this file.  Instead, make changes to \"genktab.c\".\n", outfile);
  123. fputs(" */\n", outfile);
  124. fputs("\n", outfile);
  125.  
  126. fputs("unsigned char kbtyp[] = {\n",outfile);
  127. for (i=0; i < 256; i+= 8) {
  128.     strcpy(outline,"    ");
  129.     for (j=0; j < 8; j++) {
  130.         if ((i == 248) && (j == 7)) {
  131.             sprintf(hexbuff,"0x%02x};",typebuff[i+j]);
  132.             }
  133.         else {
  134.             sprintf(hexbuff,"0x%02x,",typebuff[i+j]);
  135.             }
  136.         strcat(outline,hexbuff);
  137.         }
  138.     strcat(outline,"\n");
  139.     fputs(outline,outfile);
  140.     }
  141.  
  142. fputs("\n", outfile);
  143.  
  144. fputs("unsigned char kbstd[] = {\n",outfile);
  145. for (i=0; i < 256; i+= 8) {
  146.     strcpy(outline,"    ");
  147.     for (j=0; j < 8; j++) {
  148.         if ((i == 248) && (j == 7)) {
  149.             sprintf(hexbuff,"0x%02x};",databuff[i+j]);
  150.             }
  151.         else {
  152.             sprintf(hexbuff,"0x%02x,",databuff[i+j]);
  153.             }
  154.         strcat(outline,hexbuff);
  155.         }
  156.     strcat(outline,"\n");
  157.     fputs(outline,outfile);
  158.     }
  159.  
  160. fputs("\n", outfile);
  161.  
  162. fputs("unsigned char kbapl[] = {\n",outfile);
  163. for (i=0; i < 256; i+= 8) {
  164.     strcpy(outline,"    ");
  165.     for (j=0; j < 8; j++) {
  166.         if ((i == 248) && (j == 7)) {
  167.             sprintf(hexbuff,"0x%02x};",aplbuff[i+j]);
  168.             }
  169.         else {
  170.             sprintf(hexbuff,"0x%02x,",aplbuff[i+j]);
  171.             }
  172.         strcat(outline,hexbuff);
  173.         }
  174.     strcat(outline,"\n");
  175.     fputs(outline,outfile);
  176.     }
  177.  
  178. fputs("\n", outfile);
  179.  
  180. fputs("unsigned char ebc64[] = {\n",outfile);
  181. for (i=0; i < 64; i+= 8) {
  182.     strcpy(outline,"    ");
  183.     for (j=0; j < 8; j++) {
  184.         if ((i == 56) && (j == 7)) {
  185.             sprintf(hexbuff,"0x%02x};",ebc64[i+j]);
  186.             }
  187.         else {
  188.             sprintf(hexbuff,"0x%02x,",ebc64[i+j]);
  189.             }
  190.         strcat(outline,hexbuff);
  191.         }
  192.     strcat(outline,"\n");
  193.     fputs(outline,outfile);
  194.     }
  195.     
  196. fclose(outfile);
  197. }
  198.